#pragma once 
#include <iostream>
#include <unistd.h> 
#include <pthread.h>


class Mutex{
public:
  Mutex()
  {
    pthread_mutex_init(&_mutex,NULL);
  }
  ~Mutex()
  {
    pthread_mutex_destroy(&_mutex);
  }
public:
  void lock()
  {
    pthread_mutex_lock(&_mutex);
  }
  void unlock()
  {
    pthread_mutex_unlock(&_mutex);
  }
private:
  pthread_mutex_t _mutex;
};

class Guard{
public:
  Guard(Mutex *mutex):_lock(mutex)
  {
    _lock->lock();
  }
  ~Guard()
  {
    _lock->unlock();
  }
private:
  Mutex *_lock;
};
